#include "current_calibration.h"

#include "motor_a_adc1_current.h"
#include "motor_b_adc2_current.h"

#include "delay.h"
#include "stdio.h"


extern struct ADC1_Struct MotorA_ADC;
extern struct ADC2_Struct MotorB_ADC;


/*
 * @brief   静态电流检测
 *
 * @param   need	是否需要检测。1：需要；0：不需要。
 *
 * @return  none 
 */
void STATIC_CURRENT_CALIBRATION(uint8_t need)
{
	if(need)
	{
		uint32_t MA_A = 0, MA_B = 0, MB_A = 0, MB_B = 0;
		
		for(int i = 0; i < 20; i++)
		{
			MOTORA_ADC1StartOnce();
			MOTORB_ADC2StartOnce();
			
			delay_ms(20);
			
			MA_A = MA_A + MotorA_ADC.adDmaValue[0];
			MA_B = MA_B + MotorA_ADC.adDmaValue[1];
			
			MB_A = MB_A + MotorB_ADC.adDmaValue[0];
			MB_B = MB_B + MotorB_ADC.adDmaValue[1];
			
			printf("current calibration: %d, %d, %d, %d \r\n", MA_A, MA_B, MB_A, MB_B);
		}
		printf("mean: %d, %d, %d, %d \r\n", MA_A/20, MA_B/20, MB_A/20, MB_B/20);
		printf("mean: %d, %d, %d, %d \r\n", MA_A/20, MA_B/20, MB_A/20, MB_B/20);
		printf("mean: %d, %d, %d, %d \r\n", MA_A/20, MA_B/20, MB_A/20, MB_B/20);
	}
}

